home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Resound / EditController.m < prev    next >
Encoding:
Text File  |  1992-06-14  |  10.3 KB  |  421 lines

  1.  
  2.  
  3. #import "EditController.h"
  4. #import "Imports.h"
  5.  
  6. @implementation EditController
  7.  
  8. - Cut:sender
  9. {
  10.         [[TheFileController CurrentSoundView:self] cut:self];
  11.     [TheFileController SoundChanged: [TheFileController CurrentSound:self]];
  12.     return self;
  13. }
  14.  
  15. - Delete:sender
  16. {
  17.     [[TheFileController CurrentSoundView:self] delete:self];
  18.         [TheFileController SoundChanged: [TheFileController CurrentSound:self]];
  19.     return self;
  20. }
  21.  
  22. - SelectAll:sender
  23. {
  24.     [[TheFileController CurrentSoundView:self] selectAll:self];
  25.     return self;
  26. }
  27.  
  28. - ConvertPasteBoard:sender
  29. {
  30.     [ConvertPasteBoardPanel  makeKeyAndOrderFront:self];
  31.     [NXApp runModalFor:ConvertPasteBoardPanel];
  32.     return self;
  33. }
  34.  
  35. - CancelConvertPasteBoard:sender;
  36. {
  37.     [NXApp stopModal];
  38.     [ConvertPasteBoardPanel close];
  39.     return self;
  40. }
  41.  
  42. - OkayConvertPasteBoard:sender;
  43. {
  44.     id         TheClipSound;
  45.     int     TheFormat;
  46.     double     TheRate;
  47.     int        TheCount;
  48.     [NXApp stopModal];
  49.     [ConvertPasteBoardPanel close];
  50.     TheClipSound=[Sound newFromPasteboard];
  51.     if ([MuLawButton intValue])
  52.         {
  53.         TheFormat=SND_FORMAT_MULAW_8;
  54.         TheRate=SND_RATE_CODEC;
  55.         }
  56.     else if ([FortyButton intValue])
  57.         {
  58.         TheFormat=SND_FORMAT_LINEAR_16;
  59.         TheRate=SND_RATE_HIGH;
  60.         }
  61.     else
  62.         {
  63.         TheFormat=SND_FORMAT_LINEAR_16;
  64.         TheRate=SND_RATE_LOW;
  65.         }
  66.     
  67.     if ([MonoButton intValue])
  68.         {TheCount=1;}
  69.     else {TheCount=2;}
  70.         
  71.     if (TheClipSound!=nil)
  72.         {
  73.         [TheClipSound convertToFormat:TheFormat
  74.                          samplingRate:TheRate
  75.                          channelCount:TheCount];
  76.         [TheClipSound writeToPasteboard];
  77.         [TheClipSound free];
  78.         }
  79.     return self;
  80. }
  81. - PasteInto:sender
  82. {
  83.    [[TheFileController CurrentSoundView:self] paste:self];
  84.  [TheFileController SoundChanged: [TheFileController CurrentSound:self]];
  85.         return self;
  86. }
  87.  
  88. - Copy:sender
  89. {
  90.     [[TheFileController CurrentSoundView:self] copy:self];
  91.     return self;
  92. }
  93.  
  94. - ZoomToSelection:sender
  95. {
  96.     NXRect BoundsRect;
  97.     NXRect VisibleRect;
  98.     float ScreenWidth;
  99.     float NewReductionFactor;
  100.     NXPoint NewPoint;
  101.     int TotalNumberOfSamples;
  102.     int NumberOfSamples;
  103.     int FirstSample;
  104.     int x;
  105.     
  106.     [[TheFileController CurrentWindow:self] disableFlushWindow];
  107.     for (x=1;x<=2;x++)                // need to do twice sometimes.
  108.         {
  109.         TotalNumberOfSamples=[[TheFileController CurrentSound:self] sampleCount];
  110.         [[TheFileController CurrentSoundView:self] getSelection:&FirstSample size:&NumberOfSamples];
  111.          [[TheFileController CurrentSoundView:self] getVisibleRect: &VisibleRect];
  112.     
  113.         //Step One:  Zoom to the right reduction
  114.  
  115.         ScreenWidth=VisibleRect.size.width;
  116.         NewReductionFactor=((float)NumberOfSamples)/ScreenWidth;
  117.         [[TheFileController CurrentSoundView:self] setReductionFactor: NewReductionFactor];
  118.         
  119.         // Step Two:  Move to the right spot
  120.     
  121.         [[[TheFileController CurrentSoundView:self] superview] getDocRect: &BoundsRect];
  122.     
  123.         NewPoint.x=BoundsRect.size.width * (float) FirstSample / (float) TotalNumberOfSamples+250;
  124.                 // no idea why 250 adjusts properly... sorry for the magic number.
  125.     
  126.         [[[TheFileController CurrentSoundView:self] superview] _scrollTo: &NewPoint];
  127.                 // THIS IS A PRIVATE METHOD.  IT WILL COMPILE AS "Cannot Find Method..."
  128.                 // IGNORE THIS MESSAGE.
  129.                 
  130.         [[[TheFileController CurrentWindow:self] contentView] reflectScroll: 
  131.                 [[TheFileController CurrentSoundView:self] superview]];
  132.         [[TheFileController CurrentSoundView:self] setSelection:FirstSample size:NumberOfSamples];
  133.         [self ZoomChanged:self];
  134.         }
  135.     [[TheFileController CurrentWindow:self] reenableFlushWindow];
  136.     [[TheFileController CurrentWindow:self] display];
  137.     return self;
  138. }
  139. - ZoomSmallIn:sender;
  140. {
  141.     [self ZoomBy:17.5];
  142.     return self;
  143. }
  144.  
  145.  
  146. - ZoomLargeIn:sender;
  147. {
  148.     [self ZoomBy:2.5];
  149.     return self;
  150. }
  151.  
  152.  
  153. - ZoomSmallOut:sender;
  154. {
  155.     [self ZoomBy:-17.5];
  156.     return self;
  157. }
  158.  
  159.  
  160. - ZoomLargeOut:sender;
  161. {
  162.     [self ZoomBy:-2.5];    
  163.     return self;
  164. }
  165.  
  166.  
  167. - ZoomOut:sender
  168. {
  169.     [self ZoomBy:-10.0];
  170.     return self;
  171. }
  172.  
  173. - ZoomIn:sender
  174. {
  175.     [self ZoomBy:10.0];
  176.     return self;
  177. }
  178.  
  179. - ZoomBy: (float) ThisZoomFactor
  180. {
  181.     int FirstSample, SampleCount;
  182.     NXSize ScrollSize;
  183.     float NumberOfSamples=(float)[[TheFileController CurrentSound:self]  sampleCount];
  184.     float CurrentReductionFactor=
  185.         [[TheFileController CurrentSoundView:self] reductionFactor];
  186.     float MaximumReductionFactor;
  187.     float ZoomLimit;
  188.     float ZoomReductionFactor;
  189.     
  190.     [[[TheFileController CurrentWindow:self] contentView] getContentSize:&ScrollSize];
  191.     MaximumReductionFactor= NumberOfSamples/ScrollSize.width;
  192.     [[TheFileController CurrentSoundView:self] getSelection: &FirstSample
  193.                                                     size: &SampleCount];
  194.     
  195.  
  196.     if (ThisZoomFactor<0)
  197.         {
  198.         ZoomLimit=0-(MaximumReductionFactor+MaximumReductionFactor/ThisZoomFactor);
  199.         ZoomReductionFactor=0-CurrentReductionFactor;
  200.         }
  201.     else
  202.         {
  203.         ZoomLimit=1+MaximumReductionFactor/ThisZoomFactor;
  204.         ZoomReductionFactor=CurrentReductionFactor;
  205.         }
  206.     
  207.     if (ZoomReductionFactor>=ZoomLimit)
  208.     {
  209.     [[TheFileController CurrentSoundView:self] setReductionFactor:
  210.         (CurrentReductionFactor-MaximumReductionFactor/ThisZoomFactor)];
  211.     }
  212.     else 
  213.         {
  214.         if (ThisZoomFactor<0)
  215.             {
  216.             [self ZoomAllOut:self];
  217.             }
  218.         else
  219.             {
  220.             [self ZoomAllIn:self];
  221.             }
  222.         }
  223.     [[TheFileController CurrentSoundView:self] display];
  224.     [[TheFileController CurrentSoundView:self] setSelection:FirstSample
  225.                                                     size:SampleCount];
  226.     [self ZoomChanged:self];
  227.     return self;
  228.  
  229. }
  230.  
  231. - ZoomAllIn:sender
  232. {
  233.     int FirstSample, SampleCount;
  234.     [[TheFileController CurrentSoundView:self] getSelection: &FirstSample
  235.                                                     size: &SampleCount];
  236.     
  237.     [[TheFileController CurrentSoundView:self] setReductionFactor: 1];
  238.     [[TheFileController CurrentSoundView:self] display];
  239.     [[TheFileController CurrentSoundView:self] setSelection:FirstSample
  240.                                                     size:SampleCount];
  241.     [self ZoomChanged:self];
  242.     return self;
  243. }
  244.  
  245. - ZoomAllOut:sender
  246. {
  247.     int FirstSample, SampleCount;
  248.     NXSize ScrollSize;
  249.     float NumberOfSamples=(float)[[TheFileController CurrentSound:self]  sampleCount];
  250.     [[TheFileController CurrentSoundView:self] getSelection: &FirstSample
  251.                                                     size: &SampleCount];
  252.     
  253.     [[[TheFileController CurrentWindow:self] contentView] getContentSize:&ScrollSize];
  254.     [[TheFileController CurrentSoundView:self] setReductionFactor:
  255.             NumberOfSamples / ScrollSize.width];
  256.     [[TheFileController CurrentSoundView:self] display];
  257.     [[TheFileController CurrentSoundView:self] setSelection:FirstSample
  258.                                                     size:SampleCount];
  259.     [self ZoomChanged:self];
  260.     return self;
  261. }
  262.  
  263. - ChangeZoom:sender
  264. {
  265.     int FirstSample, SampleCount;
  266.     NXSize ScrollSize;
  267.     float NumberOfSamples=(float)[[TheFileController CurrentSound:self]  sampleCount];
  268.     float MaximumReductionFactor;
  269.     
  270.     [[[TheFileController CurrentWindow:self] contentView] getContentSize:&ScrollSize];
  271.     MaximumReductionFactor= NumberOfSamples/ScrollSize.width;
  272.     [[TheFileController CurrentSoundView:self] getSelection: &FirstSample
  273.                                                     size: &SampleCount];
  274.     
  275.     
  276.     if ([TheFileController CurrentSoundView:self]!=NULL)
  277.     {[[TheFileController CurrentSoundView:self] setReductionFactor: 
  278.         ([sender floatValue]*(MaximumReductionFactor-1)+1)];
  279.     }
  280.     [[TheFileController CurrentSoundView:self] setSelection:FirstSample size:SampleCount];
  281.     [self ZoomChanged:self];
  282.     return self;
  283. }
  284.  
  285. - ZoomChanged:sender
  286. {
  287.     NXSize ScrollSize;
  288.     float NumberOfSamples=(float)[[TheFileController CurrentSound:self]  sampleCount];
  289.     float MaximumReductionFactor;
  290.     
  291.     [[[TheFileController CurrentWindow:self] contentView] getContentSize:&ScrollSize];
  292.     MaximumReductionFactor= NumberOfSamples/ScrollSize.width;
  293.     
  294.     
  295.     if (([TheFileController CurrentSoundView:self]!=NULL)&&([ZoomWindow isVisible]))
  296.         {[ZoomSlider setFloatValue:
  297.             ([[TheFileController CurrentSoundView:self] reductionFactor]-1) /
  298.             (MaximumReductionFactor-1)];
  299.         }
  300.     [self ChangeSelection:self];
  301.     [ZoomField setFloatValue: [ZoomSlider floatValue]];
  302.     return self;
  303. }
  304.  
  305. - TurnOnMenu:sender
  306. {
  307.     [self ChangeSelection:self];
  308.     [EditButton setEnabled:YES];
  309.     [ZoomButton setEnabled:YES];
  310.     return self;
  311. }
  312.  
  313. - TurnOffMenu:sender
  314. {
  315.     [self ResetSelection:self];
  316.     [EditButton setEnabled:NO];
  317.     [ZoomButton setEnabled:NO];
  318.     return self;
  319. }
  320.  
  321. - ChangeSelection:sender
  322. {
  323.     int FirstSample, SampleCount;
  324.     float SamplingRate;
  325.     
  326.     SamplingRate = (float)[[TheFileController CurrentSound:self] samplingRate];
  327.     [[TheFileController CurrentSoundView:self] getSelection: &FirstSample
  328.                                                    size: &SampleCount];
  329.     [SelectionStart setIntValue: FirstSample];
  330.     [SelectionLength setIntValue: SampleCount];
  331.     [SelectionEnd setIntValue: FirstSample+SampleCount];
  332.     [SelectionSecondsStart setFloatValue: (float)FirstSample /SamplingRate];
  333.     [SelectionSecondsLength setFloatValue: (float)SampleCount /SamplingRate];
  334.     [SelectionSecondsEnd setFloatValue: (float)(FirstSample+SampleCount) /SamplingRate];
  335.     return self;
  336. }
  337.  
  338.  
  339. - ChangeView:sender
  340. {    
  341.     NXRect VisibleRect;
  342.     float ReductionFactor;
  343.     int FirstViewSample, ViewSampleCount;
  344.     float SamplingRate;
  345.     
  346.     SamplingRate = (float)[[TheFileController CurrentSound:self] samplingRate];
  347.     [[TheFileController CurrentSoundView:self] getVisibleRect: &VisibleRect];
  348.     ReductionFactor=[[TheFileController CurrentSoundView:self] reductionFactor];
  349.     FirstViewSample=(int) (VisibleRect.origin.x*ReductionFactor);
  350.     ViewSampleCount=(int) (VisibleRect.size.width*ReductionFactor);
  351.     [ViewStart setIntValue: FirstViewSample];
  352.     [ViewLength setIntValue: ViewSampleCount];
  353.     [ViewEnd setIntValue: FirstViewSample+ViewSampleCount];
  354.     [ViewSecondsStart setFloatValue: (float)FirstViewSample /SamplingRate];
  355.     [ViewSecondsLength setFloatValue: (float)ViewSampleCount /SamplingRate];
  356.     [ViewSecondsEnd setFloatValue: (float)(FirstViewSample+ViewSampleCount) /SamplingRate];
  357.  
  358.     
  359.     return self;
  360. }
  361.  
  362. - ResetSelection:sender
  363. {
  364.     [SelectionStart setIntValue: 0];
  365.     [SelectionLength setIntValue: 0];
  366.     [SelectionEnd setIntValue: 0];
  367.     [SelectionSecondsStart setIntValue:0];
  368.     [SelectionSecondsLength setIntValue:0];
  369.     [SelectionSecondsEnd setIntValue:0];
  370.     
  371.     [ViewStart setIntValue: 0];
  372.     [ViewLength setIntValue: 0];
  373.     [ViewEnd setIntValue: 0];
  374.     [ViewSecondsStart setIntValue:0];
  375.     [ViewSecondsLength setIntValue:0];
  376.     [ViewSecondsEnd setIntValue:0];
  377.     
  378.     return self;
  379.  
  380. }
  381.  
  382. - CompactSound:sender
  383. {
  384.     [[TheFileController CurrentSound:self] compactSamples];
  385.     [TheFileController SoundChanged: [TheFileController CurrentSound:self]];
  386.     return self;
  387. }
  388.  
  389. - SetContinuousZoom: (BOOL) ZoomOn;
  390. {
  391.     [ZoomSlider setContinuous: ZoomOn];
  392.     return self;
  393. }
  394.  
  395.  
  396. /*  IMPLEMENTED BY EDITCONTROLLER AS A DELEGATE OF PANELS */
  397.  
  398. - windowDidBecomeMain:sender
  399. {
  400.     if (sender==ZoomWindow)
  401.         {[self ZoomChanged:self];}
  402.     return self;
  403. }
  404.  
  405. - windowDidBecomeKey:sender
  406. {    
  407.     if (sender==ZoomWindow)
  408.         {[self ZoomChanged:self];}
  409.     return self;
  410. }
  411.  
  412. - windowDidDeminiaturize:sender
  413. {        
  414.     if (sender==ZoomWindow)
  415.         {[self ZoomChanged:self];}
  416.     return self;
  417. }
  418.  
  419.  
  420. @end
  421.